input 1: | input 2: |
---|---|
Rats | 12 |
Enter an integer: Rats You entered bad data. Run the program again. Good-by |
Enter an integer: 12 The square of 12 is 144 Good-by |
try{}
and catch{}
Here is ONE form of the try
/catch
structure
(there are other forms soon to be discussed):
try { // statements, some of which might // throw an exception } catch ( SomeExceptionType ex ) { // statements to handle this // type of exception } .... // more catch blocks catch ( AnotherExceptionType ex ) { // statements to handle this // type of exception } // Statements following the structure
Here are a few syntax rules:
try{}
block can include:
catch{}
blocks.
catch{}
block.
This will be discussed in a few pages.catch{}
block describes the type of exception it handles.